package com.example.weatherview

import android.util.Log
import java.io.BufferedReader
import java.io.InputStreamReader

/**
 * @author Tom.wu
 * @Description:
 * @Package: com.example.weatherview
 * @data  2024/5/28 11:09
 */
object Ping {

    const val TAG = "Ping"

     fun pingAddress(address: String) {
        Thread {
            try {
                val process = Runtime.getRuntime().exec("ping -c 4 $address")
                val reader = BufferedReader(InputStreamReader(process.inputStream))
                val output = StringBuilder()
                var line: String?
                while (reader.readLine().also { line = it } != null) {
                    output.append(line).append("\n")
                }
                reader.close()
                process.waitFor()
                Log.d(TAG, "pingAddress: ${output.toString()}")
            } catch (e: Exception) {
                Log.d(TAG, "pingAddress: $e")
            }
        }.start()
    }

}